package com.chinaztt.fda.application;

import android.app.Application;
import android.content.Context;

import com.chinaztt.fda.crash.CustomCrash;
import com.chinaztt.fda.test.glide.GlideManager;
import com.chinaztt.fda.utils.ToastUtil;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import org.androidannotations.annotations.EApplication;

import java.util.HashMap;
import java.util.Objects;

/**
 * 当前类注释:自定义全局 application 主要进全局引用,行存储全局变量,全局配置/设置,初始化等相关工作
 * 项目名：FastDev4Android
 * 包名：com.chinaztt.fda.application
 * 作者：江清清 on 15/10/22 08:50
 * 邮箱：jiangqqlmj@163.com
 * QQ： 781931404
 * 公司：江苏中天科技软件技术有限公司
 */
@EApplication
public class FDApplication extends Application {
    private HashMap<String, Objects> mTemp = new HashMap<String, Objects>();
    private static FDApplication instance;
    private GlideManager mGlideManager;

    public static FDApplication getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        this.instance = this;
        //初始化崩溃日志收集器
        CustomCrash mCustomCrash = CustomCrash.getInstance();
        //mCustomCrash.setCustomCrashInfo(this);
        initImageLoader(this);
        ToastUtil.init(this);
        mGlideManager = new GlideManager(this);
    }

    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you may tune some of them,
        // or you can create default configuration by
        //  ImageLoaderConfiguration.createDefault(this);
        // method.
        ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
        config.threadPriority(Thread.NORM_PRIORITY - 2);
        config.denyCacheImageMultipleSizesInMemory();
        config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
        config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
        config.tasksProcessingOrder(QueueProcessingType.LIFO);
        config.writeDebugLogs(); // Remove for release app

        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config.build());
    }

    public GlideManager getmGlideManager() {
        return mGlideManager;
    }
}
